import { reqAddOrUpdateShopCart, reqGoodsInfo } from "../api";
//封装游客身份模块uuid-->生成一个随机字符串(不能再改变)
// import { getUUID } from '@/utils/uuid_token'
const state = {
    //返回一个对象
    goodInfo: {},
    //游客临时身份
    // uuid_token: getUUID()
};
const mutations = {
    GETGOODINFO(state, goodInfo) {
        state.goodInfo = goodInfo;
    }
};
const actions = {
    //获取产品信息的action
    async getGoodInfo({ commit }, sid) {
        let result = await reqGoodsInfo(sid);
        console.log(result);
        if (result.code == 200) {
            commit('GETGOODINFO', result.data);
        }
    },
    //将产品添加到购物车中
    async addOrUpdateShopCart({ commit }, { sid, skuNum }) {
        //加入购物车返回的结果
        let result = await reqAddOrUpdateShopCart(sid, skuNum);
        //代表服务器加入购物车成功
        if (result.code == 200) {
            return "ok"
        } else {
            //代表加入购物车失败
            return Promise.reject(new Error('faile'));
        }
    },
};
const getters = {
    //简化数据

    // categoryView(state) {
    //     return state.goodInfo.categoryView || {};
    // },

    //简化产品信息数据
    skuInfo(state) {
        return state.goodInfo || {};
    },

    //简化产品售卖属性
    // spuSaleAttrList(state) {
    //     return state.goodInfo.shoeSizes || [];
    // }
};
export default {
    state,
    actions,
    mutations,
    getters
}